home *** CD-ROM | disk | FTP | other *** search
/ Ian & Stuart's Australian Mac: Not for Sale / Another.not.for.sale (Australia).iso / fade into you / being there / How To & FAQ's / jpeg.FAQ < prev    next >
Text File  |  1994-05-15  |  54KB  |  977 lines

  1. Archive-name: jpeg-faq
  2. Last-modified: 24 January 1993
  3.  
  4. This FAQ article discusses JPEG image compression.  Suggestions for
  5. additions and clarifications are welcome.
  6.  
  7. New since version of 10 January 1993:
  8.   * xli's new release, 1.12, has faster IJG version 4 JPEG decoder.
  9.   * New version 2.1 of Colorview for DOS.
  10.   * WinECJ is a new, remarkably fast JPEG viewer for Windows 3.1.
  11.   * Amiga compilation of IJG version 4 code is available.
  12.  
  13.  
  14. This article includes the following sections:
  15.  
  16. [1]  What is JPEG?
  17. [2]  Why use JPEG?
  18. [3]  When should I use JPEG, and when should I stick with GIF?
  19. [4]  How well does JPEG compress images?
  20. [5]  What are good "quality" settings for JPEG?
  21. [6]  Where can I get JPEG software?
  22.     [6A] "canned" software, viewers, etc.
  23.     [6B] source code
  24. [7]  What's all this hoopla about color quantization?
  25. [8]  How does JPEG work?
  26. [9]  What about lossless JPEG?
  27. [10]  Why all the argument about file formats?
  28. [11]  How do I recognize which file format I have, and what do I do about it?
  29. [12]  What about arithmetic coding?
  30. [13]  Does loss accumulate with repeated compression/decompression?
  31. [14]  What are some rules of thumb for converting GIF images to JPEG?
  32.  
  33. Sections 1-6 are basic info that every JPEG user needs to know;
  34. sections 7-14 are advanced info for the curious.
  35.  
  36. This article is posted every 2 weeks.  You can always find the latest version
  37. in the news.answers archive at rtfm.mit.edu (18.172.1.27).  By FTP, fetch
  38. /pub/usenet/news.answers/jpeg-faq; or if you don't have FTP, send e-mail to
  39. mail-server@rtfm.mit.edu with body "send usenet/news.answers/jpeg-faq".)
  40.  
  41. ----------
  42.  
  43.  
  44. [1]  What is JPEG?
  45.  
  46. JPEG (pronounced "jay-peg") is a standardized image compression mechanism.
  47. JPEG stands for Joint Photographic Experts Group, the original name of the
  48. committee that wrote the standard.  JPEG is designed for compressing either
  49. full-color or gray-scale digital images of "natural", real-world scenes.
  50. It does not work so well on non-realistic images, such as cartoons or line
  51. drawings.
  52.  
  53. JPEG does not handle black-and-white (1-bit-per-pixel) images, nor does it
  54. handle motion picture compression.  Standards for compressing those types
  55. of images are being worked on by other committees, named JBIG and MPEG
  56. respectively.
  57.  
  58. JPEG is "lossy", meaning that the image you get out of decompression isn't
  59. quite identical to what you originally put in.  The algorithm achieves much
  60. of its compression by exploiting known limitations of the human eye, notably
  61. the fact that small color details aren't perceived as well as small details
  62. of light-and-dark.  Thus, JPEG is intended for compressing images that will
  63. be looked at by humans.  If you plan to machine-analyze your images, the
  64. small errors introduced by JPEG may be a problem for you, even if they are
  65. invisible to the eye.
  66.  
  67. A useful property of JPEG is that the degree of lossiness can be varied by
  68. adjusting compression parameters.  This means that the image maker can trade
  69. off file size against output image quality.  You can make *extremely* small
  70. files if you don't mind poor quality; this is useful for indexing image
  71. archives, making thumbnail views or icons, etc. etc.  Conversely, if you
  72. aren't happy with the output quality at the default compression setting, you
  73. can jack up the quality until you are satisfied, and accept lesser compression.
  74.  
  75.  
  76. [2]  Why use JPEG?
  77.  
  78. There are two good reasons: to make your image files smaller, and to store
  79. 24-bit-per-pixel color data instead of 8-bit-per-pixel data.
  80.  
  81. Making image files smaller is a big win for transmitting files across
  82. networks and for archiving libraries of images.  Being able to compress a
  83. 2 Mbyte full-color file down to 100 Kbytes or so makes a big difference in
  84. disk space and transmission time!  (If you are comparing GIF and JPEG, the
  85. size ratio is more like four to one.  More details below.)
  86.  
  87. If your viewing software doesn't support JPEG directly, you'll have to
  88. convert JPEG to some other format for viewing or manipulating images.  Even
  89. with a JPEG-capable viewer, it takes longer to decode and view a JPEG image
  90. than to view an image of a simpler format (GIF, for instance).  Thus, using
  91. JPEG is essentially a time/space tradeoff: you give up some time in order to
  92. store or transmit an image more cheaply.
  93.  
  94. It's worth noting that when network or phone transmission is involved, the
  95. time savings from transferring a shorter file can be much greater than the
  96. extra time to decompress the file.  I'll let you do the arithmetic yourself.
  97.  
  98. The other reason why JPEG will gradually replace GIF as a standard Usenet
  99. posting format is that JPEG can store full color information: 24 bits/pixel
  100. (16 million colors) instead of 8 or less (256 or fewer colors).  If you have
  101. only 8-bit display hardware then this may not seem like much of an advantage
  102. to you.  Within a couple of years, though, 8-bit GIF will look as obsolete as
  103. black-and-white MacPaint format does today.  Furthermore, for reasons detailed
  104. in section 7, JPEG is far more useful than GIF for exchanging images among
  105. people with widely varying color display hardware.  Hence JPEG is considerably
  106. more appropriate than GIF for use as a Usenet posting standard.
  107.  
  108.  
  109. [3]  When should I use JPEG, and when should I stick with GIF?
  110.  
  111. JPEG is *not* going to displace GIF entirely; for some types of images,
  112. GIF is superior in image quality, file size, or both.  One of the first
  113. things to learn about JPEG is which kinds of images to apply it to.
  114.  
  115. As a rule of thumb, JPEG is superior to GIF for storing full-color or
  116. gray-scale images of "realistic" scenes; that means scanned photographs and
  117. similar material.  JPEG is superior even if you don't have 24-bit display
  118. hardware, and it is a LOT superior if you do.  (See section 7 for details.)
  119.  
  120. GIF does significantly better on images with only a few distinct colors,
  121. such as cartoons and line drawings.  In particular, large areas of pixels
  122. that are all *exactly* the same color are compressed very efficiently indeed
  123. by GIF.  JPEG can't squeeze these files as much as GIF does without
  124. introducing visible defects.  This sort of image is best kept in GIF form.
  125. (In particular, single-color borders are quite cheap in GIF files, but they
  126. should be avoided in JPEG files.)
  127.  
  128. JPEG also has a hard time with very sharp edges: a row of pure-black pixels
  129. adjacent to a row of pure-white pixels, for example.  Sharp edges tend to
  130. come out blurred unless you use a very high quality setting.  Again, this
  131. sort of thing is not found in scanned photographs, but it shows up fairly
  132. often in GIF files: borders, overlaid text, etc.  The blurriness is
  133. particularly objectionable with text that's only a few pixels high.
  134. If you have a GIF with a lot of small-size overlaid text, don't JPEG it.
  135.  
  136. Computer-drawn images (ray-traced scenes, for instance) usually fall between
  137. scanned images and cartoons in terms of complexity.  The more complex and
  138. subtly rendered the image, the more likely that JPEG will do well on it.
  139. The same goes for semi-realistic artwork (fantasy drawings and such).
  140.  
  141. Plain black-and-white (two level) images should never be converted to JPEG.
  142. You need at least about 16 gray levels before JPEG is useful for gray-scale
  143. images.  It should also be noted that GIF is lossless for gray-scale images
  144. of up to 256 levels, while JPEG is not.
  145.  
  146. If you have an existing library of GIF images, you may wonder whether you
  147. should convert them to JPEG.  You will lose a little image quality if you do.
  148. (Section 7, which argues that JPEG image quality is superior to GIF, only
  149. applies if both formats start from a full-color original.  If you start from
  150. a GIF, you've already irretrievably lost a great deal of information; JPEG
  151. can only make things worse.)  However, the disk space savings may justify
  152. converting anyway.  This is a decision you'll have to make for yourself.
  153. If you do convert a GIF library to JPEG, see section 14 for hints.  Be
  154. prepared to leave some images in GIF format, since some GIFs will not
  155. convert well.
  156.  
  157.  
  158. [4]  How well does JPEG compress images?
  159.  
  160. Pretty darn well.  Here are some sample file sizes for an image I have
  161. handy, a 727x525 full-color image of a ship in a harbor.  The first three
  162. files are for comparison purposes; the rest were created with the free JPEG
  163. software described in section 6B.
  164.  
  165. File       Size in bytes        Comments
  166.  
  167. ship.ppm    1145040  Original file in PPM format (no compression; 24 bits
  168.              or 3 bytes per pixel, plus a few bytes overhead)
  169. ship.ppm.Z     963829  PPM file passed through Unix compress
  170.              compress doesn't accomplish a lot, you'll note.
  171.              Other text-oriented compressors give similar results.
  172. ship.gif     240438  Converted to GIF with ppmquant -fs 256 | ppmtogif
  173.              Most of the savings is the result of losing color
  174.              info: GIF saves 8 bits/pixel, not 24.  (See sec. 7.)
  175.  
  176. ship.jpg95     155622  cjpeg -Q 95    (highest useful quality setting)
  177.              This is indistinguishable from the 24-bit original,
  178.              at least to my nonprofessional eyeballs.
  179. ship.jpg75      58009  cjpeg -Q 75    (default setting)
  180.              You have to look mighty darn close to distinguish this
  181.              from the original, even with both on-screen at once.
  182. ship.jpg50      38406  cjpeg -Q 50
  183.              This has slight defects; if you know what to look
  184.              for, you could tell it's been JPEGed without seeing
  185.              the original.  Still as good image quality as many
  186.              recent postings in Usenet pictures groups.
  187. ship.jpg25      25192  cjpeg -Q 25
  188.              JPEG's characteristic "blockiness" becomes apparent
  189.              at this setting (djpeg -blocksmooth helps some).
  190.              Still, I've seen plenty of Usenet postings that were
  191.              of poorer image quality than this.
  192. ship.jpg5o       6587  cjpeg -Q 5 -optimize  (-optimize cuts table overhead)
  193.              Blocky, but perfectly satisfactory for preview or
  194.              indexing purposes.  Note that this file is TINY:
  195.              the compression ratio from the original is 173:1 !
  196.  
  197. In this case JPEG can make a file that's a factor of four or five smaller
  198. than a GIF of comparable quality (the -Q 75 file is every bit as good as the
  199. GIF, better if you have a full-color display).  This seems to be a typical
  200. ratio for real-world scenes.
  201.  
  202.  
  203. [5]  What are good "quality" settings for JPEG?
  204.  
  205. (Note: the quality settings discussed in this article apply to the free JPEG
  206. software described in section 6B.  Other JPEG implementations, such as Image
  207. Alchemy, may use a completely different quality scale.)
  208.  
  209. The name of the game in using JPEG is to pick the lowest quality setting
  210. (smallest file size) that decompresses into an image indistinguishable from
  211. the original.  This setting will vary from one image to another and from one
  212. observer to another, but here are some rules of thumb.
  213.  
  214. The default quality setting (-Q 75) is very often the best choice.  This
  215. setting is about the lowest you can go without expecting to see defects in a
  216. typical image.  Try -Q 75 first; if you see defects, then go up.  Except for
  217. experimental purposes, never go above -Q 95; saying -Q 100 will produce a
  218. file two or three times as large as -Q 95, but of hardly any better quality.
  219.  
  220. If the image was less than perfect quality to begin with, you might be able to
  221. go down to -Q 50 without objectionable degradation.  On the other hand, you
  222. might need to go to a HIGHER quality setting to avoid further degradation.
  223. The second case seems to apply much of the time when converting GIFs to JPEG.
  224. The default -Q 75 is about right for compressing 24-bit images, but -Q 85 to
  225. 95 is usually better for converting GIFs (see section 14 for more info).
  226.  
  227. If you want a very small file (say for preview or indexing purposes) and are
  228. prepared to tolerate large defects, a -Q setting in the range of 5 to 10 is
  229. about right.  -Q 2 or so may be amusing as "op art".
  230.  
  231.  
  232. [6]  Where can I get JPEG software?
  233.  
  234. [6A]  If you are looking for "canned" software, viewers, etc:
  235.  
  236. The first part of this list is system-specific programs that only run on one
  237. kind of system.  If you don't see what you want for your machine, check out
  238. the portable JPEG software described at the end of the list.  Note that this
  239. list concentrates on free and shareware programs that you can obtain over
  240. Internet; but some commercial programs are listed too.
  241.  
  242. X Windows:
  243.  
  244. John Bradley's free XV (version 2.00 and up) is an excellent viewer for JPEG,
  245. GIF, and other image formats.  It's available for FTP from export.lcs.mit.edu
  246. or ftp.cis.upenn.edu.  The file is called 'xv-???.tar.Z' (where ??? is the
  247. version number, currently 2.21); it is located in the 'contrib' directory on
  248. export or the 'pub/xv' directory at upenn.  XV reduces all images to 8 bits
  249. internally, which means it's not a real good choice if you have a 24-bit
  250. display (you'll still get only 8-bit color).  Also, you shouldn't use XV to
  251. convert full-color images to JPEG, because they'll get color-quantized first.
  252. But XV is a fine tool for converting GIF and other 8-bit images to JPEG.
  253. CAUTION: there is a glitch in versions 2.21 and earlier: be sure to check
  254. the "save at normal size" checkbox when saving a JPEG file, or the file will
  255. be blurry.
  256.  
  257. Another good choice for X Windows is John Cristy's free ImageMagick package,
  258. also available from export.lcs.mit.edu, file contrib/ImageMagick.tar.Z.
  259. This package handles many image processing and conversion tasks.  The
  260. ImageMagick viewer handles 24-bit displays correctly; for colormapped
  261. displays, it does better (though slower) color quantization than XV or the
  262. basic free JPEG software.
  263.  
  264. Both of the above are large, complex packages.  If you just want a simple
  265. image viewer, try xloadimage or xli.  xloadimage supports JPEG in its latest
  266. release, 3.03.  xloadimage is free and available from export.lcs.mit.edu,
  267. file contrib/xloadimage.3.03.tar.Z.  xli is a variant version of xloadimage,
  268. said by its fans to be somewhat faster and more robust than the original.
  269. (The current xli is indeed faster and more robust than the current
  270. xloadimage, at least with respect to JPEG files, because it has the IJG v4
  271. decoder while xloadimage 3.03 is using a hacked-over v1.  The next
  272. xloadimage release will fix this.)  xli is also free and available from
  273. export.lcs.mit.edu, file contrib/xli.1.12.tar.Z.  Both programs are said
  274. to do the right thing with 24-bit displays.
  275.  
  276.  
  277. MS-DOS:
  278.  
  279. This covers plain DOS; for Windows programs, see the next heading.
  280.  
  281. One good choice is Eric Praetzel's free DVPEG, which views JPEG and GIF files.
  282. The current version, 2.1, is available by FTP from sunee.waterloo.edu
  283. (129.97.50.50), file pub/jpeg/viewers/dvpeg21.zip.  This is a good basic
  284. viewer that works on either 286 or 386/486 machines.  The user interface is
  285. not flashy, but it's functional.
  286.  
  287. Another freeware JPEG/GIF/TGA viewer is Mohammad Rezaei's Hiview.  The
  288. current version, 1.2, is available from Simtel20 and mirror sites (see NOTE
  289. below), file msdos/graphics/hv12.zip.  Hiview requires a 386 or better CPU
  290. and a VCPI-compatible memory manager (QEMM386 and 386MAX work; Windows and
  291. OS/2 do not).  Hiview is currently the fastest viewer for images that are no
  292. bigger than your screen.  For larger images, it scales the image down to fit
  293. on the screen (rather than using panning/scrolling as most viewers do).
  294. You may or may not prefer this approach, but there's no denying that it
  295. slows down loading of large images considerably.  Note: installation is a
  296. bit tricky; read the directions carefully!
  297.  
  298. A shareware alternative is ColorView for DOS ($30).  This is easier to
  299. install than either of the two freeware alternatives.  Its user interface is
  300. also much spiffier-looking, although personally I find it harder to use ---
  301. more keystrokes, inconsistent behavior.  It is faster than DVPEG but a
  302. little slower than Hiview, at least on my hardware.  (For images larger than
  303. screen size, DVPEG and ColorView seem to be about the same speed, and both
  304. are faster than Hiview.)  The current version is 2.1, available from
  305. Simtel20 and mirror sites (see NOTE below), file msdos/graphics/dcview21.zip.
  306. Requires a VESA graphics driver; if you don't have one, look in vesadriv.zip
  307. or vesadrv2.zip from the same directory.
  308.  
  309. A second shareware alternative is Fullview, which has been kicking around
  310. the net for a while, but I don't know any stable archive location for it.
  311. The author tells me that a new version of Fullview will be out shortly
  312. and it will be submitted to the Simtel20 archives at that time.
  313.  
  314. If none of these viewers work on your hardware, you'll need to use one of
  315. the following conversion programs to convert JPEG to GIF, then view with
  316. your favorite GIF viewer.  (If you have hi-color hardware, don't use GIF
  317. as the intermediate format; try to find a TARGA-capable viewer instead.
  318. VPIC5.0 is reputed to do the right thing with hi-color displays.)
  319.  
  320. The Independent JPEG Group's free JPEG converters are FTPable from Simtel20
  321. and mirror sites (see NOTE below), file msdos/graphics/jpeg3.zip (or
  322. jpeg3386.zip if you have a 386 and extended memory).  The same files were
  323. posted to comp.binaries.ibm.pc (volume 18, issues 123-130) and should be
  324. available from any c.b.i.p archive site.  These files are DOS compilations
  325. of the free source code described in section 6B.  (Version 4 compilations
  326. will be out shortly.)
  327.  
  328. Handmade Software offers two shareware conversion programs: Image Alchemy
  329. and GIF2JPG/JPG2GIF (contact hsi@netcom.com for details).  The PC versions
  330. of these programs are FTPable from Simtel20 and mirror sites (see NOTE
  331. below), files msdos/graphics/alch16.zip and gif2jpg5.zip.  GIF2JPG/JPG2GIF
  332. only performs JPEG<=>GIF format conversion.  Image Alchemy converts files
  333. between these and many other formats, and can also display images on some
  334. types of hardware.  The display option is limited and not very high quality,
  335. so you'll still want a separate viewer program.  (CAUTION: GIF2JPG produces
  336. a proprietary file format unless you specify -j.  Be sure to use -j if you
  337. want to exchange JPEG files with other Usenet users.)  In my biased opinion,
  338. the free JPEG software is a better choice than GIF2JPG/JPG2GIF; it's faster,
  339. as good or better image quality, and free :-).  On the other hand, Image
  340. Alchemy may be worth its price, if you need the additional conversion and
  341. image manipulation capabilities it provides.
  342.  
  343. NOTE ABOUT SIMTEL20: The Internet's key archive site for PC-related programs
  344. is Simtel20, full name wsmr-simtel20.army.mil (192.88.110.20).  Simtel20
  345. runs a non-Unix operating system; where this document refers to directory
  346. (eg) "msdos/graphics" at Simtel20, that really means "pd1:<msdos.graphics>".
  347. If you are not physically on MILnet, you should expect rather slow FTP
  348. transfer rates from Simtel20.  There are several Internet sites that
  349. maintain copies (mirrors) of the Simtel20 archives; most FTP users should
  350. go to one of the mirror sites instead.  A popular USA mirror site is
  351. oak.oakland.edu (141.210.10.117); it keeps Simtel20 files in (eg)
  352. "/pub/msdos/graphics".  If you have no FTP capability, you can retrieve
  353. files from Simtel20 by e-mail; see informational postings in
  354. comp.binaries.ibm.pc.archives to find out how.  If you are outside the USA,
  355. consult the same newsgroup to learn where your nearest Simtel20 mirror is.
  356.  
  357. Microsoft Windows:
  358.  
  359. There are several Windows programs capable of displaying JPEG images.
  360. (These will probably work under OS/2 also, but I have not tried it.)
  361.  
  362. The newest entry is WinECJ, which is free and EXTREMELY fast.  Version 1.0
  363. is available from ftp.rahul.net, file /pub/bryanw/pc/jpeg/wecj.exe.
  364. Requires Windows 3.1 and 256-or-more-colors mode.  This is a no-frills
  365. viewer with the bad habit of hogging the machine completely while it
  366. decodes; and the image quality is noticeably worse than other viewers.
  367. But it's so fast you'll use it anyway, at least for previewing...
  368.  
  369. JView is freeware, fairly fast, has good on-line help, and can write out the
  370. decompressed image in Windows BMP format; but it can't create new JPEG
  371. files, and it doesn't view GIFs.  JView also lacks some other useful
  372. features of the shareware viewers (such as brightness adjustment), but it's
  373. an excellent basic viewer.  The current version, 0.9, is available from
  374. ftp.cica.indiana.edu (129.79.20.84), file pub/pc/win3/desktop/jview090.zip.
  375. (Mirrors of this archive can be found at some other Internet sites,
  376. including wuarchive.wustl.edu.)
  377.  
  378. WinJPEG (shareware, $20) displays JPEG, GIF, Targa, and BMP image files;
  379. it can write all of these formats too, so it can be used as a converter.
  380. It has some other nifty features including color-balance adjustment and
  381. slideshow.  The current version is 1.6, available from Simtel20 and mirror
  382. sites (see NOTE above), file msdos/windows3/winjp160.zip.  (This is a slow
  383. 286-compatible version; if you register, you'll get the 386-only version,
  384. which is roughly 25% faster.)
  385.  
  386. ColorView is another shareware entry ($30).  This was an early and promising
  387. contender, but it has not been updated in some time, and at this point it
  388. has no real advantages over WinJPEG.  If you want to try it anyway, the
  389. current version is 0.97, available from ftp.cica.indiana.edu, file
  390. pub/pc/win3/desktop/cview097.zip.  (I understand that a new version will
  391. be appearing once the authors are finished with ColorView for DOS.)
  392.  
  393. The DOS conversion programs described above will run inside a Windows DOS
  394. window.  DVPEG also works under Windows (in full-screen mode, not in a
  395. window).  Note that Windows viewers are generally slower than non-Windows
  396. viewers on the same hardware, due to Windows' system overhead.
  397.  
  398. Macintosh:
  399.  
  400. Most Mac JPEG programs rely on Apple's JPEG implementation, which is part of
  401. the QuickTime system extension; so you need to have QuickTime installed.
  402. To use QuickTime, you need a 68020 or better CPU and you need to be running
  403. System 6.0.7 or later.  (If you're running System 6, you must also install
  404. the 32-bit QuickDraw extension; this is built-in on System 7.)  You can get
  405. QuickTime by FTP from ftp.apple.com, file dts/mac/quicktime/quicktime.hqx.
  406. (As of 11/92, this file contains QuickTime 1.5, which is better than QT 1.0
  407. in several ways.  With respect to JPEG, it is marginally faster and
  408. considerably less prone to crash when fed a corrupt JPEG file.  However,
  409. some applications seem to have compatibility problems with QT 1.5.)
  410.  
  411. The first choice is probably JPEGView, a free program for viewing images
  412. that are in Usenet-standard JFIF JPEG format, QuickTime's internal JPEG
  413. format (PICT/JPEG), or GIF format.  It can also convert between the two
  414. JPEG formats.  The current version, 2.0, is a big improvement over prior
  415. versions.  Get it from sumex-aim.stanford.edu (36.44.0.6), file
  416. /info-mac/app/jpeg-view-20.hqx.  Requires System 7 and QuickTime.  On 8-bit
  417. displays, JPEGView usually produces the best color image quality of all the
  418. currently available Mac JPEG viewers.  JPEGView can view large images in
  419. much less memory than other Mac viewers; in fact, it's the only one that can
  420. deal with JPEG images much over 640x480 pixels on a typical 4MB Mac.  Given
  421. a large image, JPEGView automatically scales it down to fit on the screen,
  422. rather than presenting scroll bars like most other viewers.  (You can zoom
  423. in on any desired portion, though.)  Some people like this behavior, some
  424. don't.  Overall, JPEGView's user interface is very well thought out.
  425.  
  426. GIFConverter, a shareware ($40) image viewer/converter, supports JPEG in its
  427. latest release (2.3b2).  GIFConverter offers very nice viewing and
  428. format-conversion features, but 2.3b2 is a beta version and may have a few
  429. bugs still lurking.  Get it from sumex-aim.stanford.edu, file
  430. /info-mac/art/gif/gif-converter-23b2.hqx.  GIFConverter is not better than
  431. JPEGView 2.0 as a plain JPEG/GIF viewer, but it has more image manipulation
  432. and format conversion capabilities, so you may find it worth its shareware
  433. fee if you do a lot of playing around with images.  GIFConverter does *not*
  434. require System 7, but it does need QuickTime to view JPEGs.  (This
  435. restriction is expected to go away in the next release, whereupon
  436. GIFConverter will become the JPEG viewer of choice for QuickTime-less Macs.)
  437.  
  438. Apple's free program PictPixie can view images in JFIF, QuickTime JPEG, and
  439. GIF format, and can convert between these formats.  You can get PictPixie
  440. from ftp.apple.com, file dts/mac/quicktime/qt.1.0.stuff/pictpixie.hqx.
  441. Requires QuickTime.  PictPixie was intended as a developer's tool, and it's
  442. really not the best choice unless you like to fool around with QuickTime.
  443. Some of its drawbacks are that it requires lots of memory, it produces
  444. relatively poor color image quality on anything less than a 24-bit display,
  445. and it has a relatively unfriendly user interface.  Worse, PictPixie is an
  446. unsupported program, meaning it has some minor bugs that Apple does not
  447. intend to fix.  (There is an old version of PictPixie, called
  448. PICTCompressor, floating around the net.  If you have this you should trash
  449. it, as it's even buggier.  Also, the QuickTime Starter Kit includes a much
  450. cleaned-up descendant of PictPixie called Picture Compressor.  Note that
  451. Picture Compressor is NOT free and may not be distributed on the net.)
  452.  
  453. Storm Technology's Picture Decompress is a free JPEG viewer/converter.
  454. This program is old and is much inferior to the above programs in speed,
  455. features, image quality, and memory demands, but it will run without System
  456. 7 or QuickTime, so you may be forced to use it on older systems.  (You'll
  457. still need 32-bit QuickDraw.)  You can get it from sumex-aim.stanford.edu,
  458. file /info-mac/app/picture-decompress-201.hqx.  You'll also need a tool for
  459. adjusting file type codes; you must set the type of a downloaded image file
  460. to 'JPEG' to allow Picture Decompress to open it.
  461.  
  462. If your Mac is too old to run either QuickTime or 32-bit QuickDraw (a Mac
  463. Plus for instance), things are pretty grim.  You can try Jeff Lewis's
  464. Imagery JPEG, which will convert from JPEG to GIF; it's available from
  465. sumex-aim.stanford.edu, file /info-mac/app/imagery-jpeg-gif-conv-06.hqx.
  466. The color output quality of this program is terrible, but grayscale output
  467. should be OK, and that's all you'll need anyway.  Things should get better
  468. when the next release of GIFConverter comes out.
  469.  
  470. More and more commercial Mac applications are supporting JPEG, although not
  471. all can deal with the Usenet-standard JFIF format.  Adobe Photoshop, version
  472. 2.0.1 or later, can read and write JFIF-format JPEG files (use the JPEG
  473. plug-in from the Acquire menu).  You must set the file type of a downloaded
  474. JPEG file to 'JPEG' to allow Photoshop to recognize it.
  475.  
  476. Amiga:
  477.  
  478. (Most programs listed in this section are stored in the AmiNet archive at
  479. amiga.physik.unizh.ch (130.60.80.80).  There are many mirror sites of this
  480. archive and you should try to use the closest one.  In the USA, a good
  481. choice is wuarchive.wustl.edu; look under /mirrors/amiga.physik.unizh.ch/...)
  482.  
  483. HamLab Plus is an excellent JPEG viewer/converter, as well as being a
  484. general image manipulation tool.  It's cheap (shareware, $20) and can read
  485. several formats besides JPEG.  The current version is 2.0.8.  A demo version
  486. is available from amiga.physik.unizh.ch (and mirror sites), file
  487. amiga/gfx/edit/hamlab208d.lha.  The demo version will crop images larger
  488. than 512x512, but it is otherwise fully functional.
  489.  
  490. Rend24 (shareware, $30) is an image renderer that can display JPEG, ILBM,
  491. and GIF images.  The program can be used to create animations, even
  492. capturing frames on-the-fly from rendering packages like Lightwave.  The
  493. current version is 1.05, available from amiga.physik.unizh.ch (and mirror
  494. sites), file amiga/os30/gfx/rend105.lha.  (Note: although this directory is
  495. supposedly for AmigaDOS 3.0 programs, the program will also run under
  496. AmigaDOS 1.3, 2.04 or 2.1.)
  497.  
  498. Viewtek is a free JPEG/ILBM/GIF viewer.  The current version is 1.03,
  499. available from amiga.physik.unizh.ch (and mirror sites), file
  500. amiga/os30/gfx/viewtek103.lha.  (Note: although this directory is supposedly
  501. for AmigaDOS 3.0 programs, the program will run under 2.04 or 2.1.)
  502.  
  503. If you're willing to spend real money, there are several commercial packages
  504. that support JPEG.  Two are written by Thomas Krehbiel, the author of Rend24
  505. and Viewtek.  These are CineMorph, a standalone image morphing package, and
  506. ImageFX, an impressive 24-bit image capture, conversion, editing, painting,
  507. effects and prepress package that also includes CineMorph.  Both are
  508. distributed by Great Valley Products.  Art Department Professional (ADPro),
  509. from ASDG Inc, is the most widely used commercial image manipulation
  510. software for Amigas.  ImageMaster, from Black Belt Systems, is another
  511. well-regarded commercial graphics package with JPEG support.
  512.  
  513. The free IJG JPEG software is available compiled for Amigas from
  514. amiga.physik.unizh.ch (and mirror sites) in directory amiga/gfx/conv, file
  515. AmigaJPEGV4.lha.  These programs convert JPEG to/from PPM,GIF,Targa formats.
  516.  
  517. The Amiga world is heavily infested with quick-and-dirty JPEG programs, many
  518. based on an ancient beta-test version of the free IJG JPEG software (thanks
  519. to a certain magazine that published same on its disk-of-the-month, without
  520. so much as notifying the authors).  Among these are "AugJPEG", "NewAmyJPEG",
  521. "VJPEG", and probably others I have not even heard of.  In my opinion,
  522. anything older than IJG version 3 (March 1992) is not worth the disk space
  523. it's stored on; if you have such a program, trash it and get something newer.
  524.  
  525. Acorn Archimedes:
  526.  
  527. !ChangeFSI, supplied with RISC OS 3 version 3.10, can convert from and view
  528. JPEG JFIF format.  Provision is also made to convert images to JPEG,
  529. although this must be done from the CLI rather than by double-clicking.
  530.  
  531. Recent versions (since 7.11) of the shareware program Translator can handle
  532. JPEG, along with about 30 other image formats.  While older versions can be
  533. found on some Archimedes bboards, the current version is only available by
  534. registering with the author, John Kortink, Nutterbrink 31, 7544 WJ, Enschede,
  535. The Netherlands.  Price 35 Dutch guilders (about $22 or 10 pounds).
  536.  
  537. There's also a commercial product called !JPEG which provides JPEG read/write
  538. functionality and direct JPEG viewing, as well as a host of other image
  539. format conversion and processing options.  This is more expensive but not
  540. necessarily better than the above programs.  Contact: DT Software, FREEPOST,
  541. Cambridge, UK.  Tel: 0223 841099.
  542.  
  543.  
  544. Portable software for almost any system:
  545.  
  546. If none of the above fits your situation, you can obtain and compile the free
  547. JPEG conversion software described in 6B.  You'll also need a viewer program.
  548. If your display is 8 bits or less, any GIF viewer will do fine; if you have a
  549. display with more color capability, try to find a viewer that can read Targa
  550. or PPM 24-bit image files.
  551.  
  552. If you are not reasonably handy at configuring and installing portable C
  553. programs, you may have some difficulty installing the free source code.
  554. Steve Davis (strat@cis.ksu.edu) has volunteered to maintain an archive of
  555. pre-built executable versions of the free JPEG code for various machines.
  556. His FTP archive is at ftp.cis.ksu.edu (129.130.10.80); look under /pub/JPEG
  557. to see what he currently has.  (The administrators of this system ask that
  558. FTP traffic be limited to non-prime hours.)  This archive is not maintained
  559. by the Independent JPEG Group, and files in it may not represent the latest
  560. free source code.  (Actually, Steve has gotten pretty lax about maintaining
  561. his archive.  Any volunteers to set up a new one?)
  562.  
  563. There are numerous commercial JPEG offerings, with more popping up every
  564. day.  I recommend that you not spend money on one of these unless you find
  565. the available free or shareware software vastly too slow.  In that case,
  566. purchase a hardware-assisted product.  Ask pointed questions about whether
  567. the product complies with the final JPEG standard and about whether it can
  568. handle the JFIF file format; many of the earliest commercial releases are
  569. not and never will be compatible with anyone else's files.
  570.  
  571.  
  572. [6B]  If you are looking for source code to work with:
  573.  
  574. Free, portable C code for JPEG compression is available from the Independent
  575. JPEG Group, which I lead.  A package containing our source code,
  576. documentation, and some small test files is available from several places.
  577. The "official" archive site for this source code is ftp.uu.net (137.39.1.9
  578. or 192.48.96.9).  Look under directory /graphics/jpeg; the current release
  579. is jpegsrc.v4.tar.Z.  (This is a compressed TAR file; don't forget to
  580. retrieve in binary mode.)  You can retrieve this file by FTP or UUCP.
  581. If you are on a PC and don't know how to cope with .tar.Z format, you may
  582. prefer ZIP format, which you can find at Simtel20 and mirror sites (see NOTE
  583. above), file msdos/graphics/jpegsrc4.zip.  This file will also be available on
  584. CompuServe, in the GRAPHSUPPORT forum (GO PICS), library 15, as jpsrc4.zip.
  585. If you have no FTP access, you can retrieve the source from your nearest
  586. comp.sources.misc archive; version 4 appeared as issues 55-72 of volume 34.
  587. (If you don't know how to retrieve comp.sources.misc postings, see the FAQ
  588. article "How to find sources".  This appears regularly in news.answers, or
  589. you can get it by sending e-mail to mail-server@rtfm.mit.edu with
  590. "send usenet/news.answers/finding-sources" in the body.)
  591.  
  592. The free JPEG code provides conversion between JPEG "JFIF" format and image
  593. files in GIF, PBMPLUS PPM/PGM, Utah RLE, and Truevision Targa file formats.
  594. The core compression and decompression modules can easily be reused in other
  595. programs, such as image viewers.  The package is highly portable; we have
  596. tested it on many machines ranging from PCs to Crays.
  597.  
  598. We have released this software for both noncommercial and commercial use.
  599. Companies are welcome to use it as the basis for JPEG-related products.
  600. We do not ask a royalty, although we do ask for an acknowledgement in
  601. product literature (see the README file in the distribution for details).
  602. We hope to make this software industrial-quality --- although, as with
  603. anything that's free, we offer no warranty and accept no liability.
  604.  
  605. The Independent JPEG Group is a volunteer organization; if you'd like to
  606. contribute to improving our software, you are welcome to join.
  607.  
  608.  
  609. [7]  What's all this hoopla about color quantization?
  610.  
  611. Most people don't have full-color (24 bit per pixel) display hardware.
  612. Typical display hardware stores 8 or fewer bits per pixel, so it can display
  613. 256 or fewer distinct colors at a time.  To display a full-color image, the
  614. computer must map the image into an appropriate set of representative
  615. colors.  This process is called "color quantization".  (This is something
  616. of a misnomer, "color selection" would be a better term.  We're stuck with
  617. the standard usage though.)
  618.  
  619. Clearly, color quantization is a lossy process.  It turns out that for most
  620. images, the details of the color quantization algorithm have MUCH more impact
  621. on the final image quality than do any errors introduced by JPEG (except at
  622. the very lowest JPEG quality settings).
  623.  
  624. Since JPEG is a full-color format, converting a color JPEG image for display
  625. on 8-bit-or-less hardware requires color quantization.  This is true for
  626. *all* color JPEGs: even if you feed a 256-or-less-color GIF into JPEG, what
  627. comes out of the decompressor is *not* 256 colors, but thousands of colors.
  628. JPEG's lossiness affects each pixel a little differently, so two pixels that
  629. started with identical colors will probably come out with slightly different
  630. colors.  Each original color gets "smeared" into a group of nearby colors.
  631. Therefore quantization is always required to display a color JPEG on a
  632. colormapped display, regardless of the image source.  The only way to avoid
  633. quantization is to ask for gray-scale output.  (Incidentally, because of
  634. this effect it's pretty much meaningless to talk about the number of colors
  635. used by a JPEG image.  I occasionally see posted images described as
  636. "256-color JPEG".  This tells me that the poster (a) hasn't read this FAQ
  637. and (b) probably converted the JPEG from a GIF.)
  638.  
  639. On the other hand, a GIF image by definition has already been quantized to
  640. 256 or fewer colors.  For purposes of Usenet picture distribution, GIF has
  641. the advantage that the sender precomputes the color quantization, so
  642. recipients don't have to.  This is also the *disadvantage* of GIF: you're
  643. stuck with the sender's quantization.  If the sender quantized to a
  644. different number of colors than what you can display, you have to
  645. re-quantize, resulting in much poorer image quality than if you had
  646. quantized once from a full-color image.  Furthermore, if the sender didn't
  647. use a high-quality color quantization algorithm, you're out of luck.
  648.  
  649. For this reason, JPEG offers the promise of significantly better image quality
  650. for all users whose machines don't match the sender's display hardware.
  651. JPEG's full color image can be quantized to precisely match the user's display
  652. hardware.  Furthermore, you will be able to take advantage of future
  653. improvements in quantization algorithms (there is a lot of active research in
  654. this area), or purchase better display hardware, to get a better view of JPEG
  655. images you already have.  With a GIF, you're stuck forevermore with what was
  656. sent.
  657.  
  658. It's also worth mentioning that many GIF-viewing programs include rather
  659. shoddy quantization routines.  If you view a 256-color GIF on a 16-color EGA
  660. display, for example, you are probably getting a much worse image than you
  661. need to.  This is partly an inevitable consequence of doing two color
  662. quantizations (one to create the GIF, one to display it), but often it's
  663. also due to sloppiness.  JPEG conversion programs will be forced to use
  664. high quality quantizers in order to get acceptable results at all, and in
  665. normal use they will quantize directly to the number of colors to be
  666. displayed.  Thus, JPEG is likely to provide better results than the average
  667. GIF program for low-color-resolution displays as well as high-resolution ones!
  668.  
  669. Finally, an ever-growing number of people have better-than-8-bit display
  670. hardware already: 15-bit "hi-color" PC displays, true 24-bit displays on
  671. workstations and Macintoshes, etc.  For these people, GIF is already
  672. obsolete, as it cannot represent an image to the full capabilities of their
  673. display.  JPEG images can drive these displays much more effectively.
  674. Thus, JPEG is an all-around better choice than GIF for representing images
  675. in a machine-independent fashion.
  676.  
  677.  
  678. [8]  How does JPEG work?
  679.  
  680. The buzz-words to know are chrominance subsampling, discrete cosine
  681. transforms, coefficient quantization, and Huffman or arithmetic entropy
  682. coding.  This article's long enough already, so I'm not going to say more
  683. than that.  For a good technical introduction, see:
  684.     Wallace, Gregory K.  "The JPEG Still Picture Compression Standard",
  685.     Communications of the ACM, April 1991 (vol. 34 no. 4), pp. 30-44.
  686. (Adjacent articles in that issue discuss MPEG motion picture compression,
  687. applications of JPEG, and related topics.)  If you don't have the CACM issue
  688. handy, a PostScript file containing a revised version of this article is
  689. available at ftp.uu.net, graphics/jpeg/wallace.ps.Z.  The file (actually a
  690. preprint for an article to appear in IEEE Trans. Consum. Elect.) omits the
  691. sample images that appeared in CACM, but it includes corrections and some
  692. added material.  Note: the Wallace article is copyright ACM and IEEE, and
  693. it may not be used for commercial purposes.
  694.  
  695. An alternative, more leisurely explanation of JPEG can be found in "The Data
  696. Compression Book" by Mark Nelson, published by M&T Books (Redwood City, CA),
  697. 1991, ISBN 1-55851-216-0.  This book provides excellent introductions to
  698. many data compression methods including JPEG, plus sample source code in C.
  699. The JPEG-related source code is far from industrial-strength, but it's a
  700. pretty good learning tool.  (When you are ready to look at a real
  701. implementation, see section 6B above.)
  702.  
  703. A new textbook about JPEG is "JPEG Still Image Data Compression Standard" by
  704. William B. Pennebaker and Joan L. Mitchell, published by Van Nostrand
  705. Reinhold, 1993, ISBN 0-442-01272-1.  Price US$59.95.  This book includes the
  706. complete text of the ISO JPEG standards (DIS 10918-1 and draft DIS 10918-2).
  707. This is by far the most complete exposition of JPEG in existence, and I highly
  708. recommend it.  If you read the entire book, you will probably know more about
  709. JPEG than I do.
  710.  
  711.  
  712. [9]  What about lossless JPEG?
  713.  
  714. There's a great deal of confusion on this subject.  The JPEG committee did
  715. define a truly lossless compression algorithm, i.e., one that guarantees the
  716. final output is bit-for-bit identical to the original input.  However, this
  717. lossless mode has almost nothing in common with the regular, lossy JPEG
  718. algorithm, and it offers much less compression.  At present, very few
  719. implementations of lossless JPEG exist, and all of them are commercial.
  720.  
  721. Saying "-Q 100" to the free JPEG software DOES NOT get you a lossless image.
  722. What it does get rid of is deliberate information loss in the coefficient
  723. quantization step.  There is still a good deal of information loss in the
  724. color subsampling step.  (With the V4 free JPEG code, you can also say
  725. "-sample 1x1" to turn off subsampling.  Keep in mind that many commercial
  726. JPEG implementations cannot cope with the resulting file.)
  727.  
  728. Even with both quantization and subsampling turned off, the regular JPEG
  729. algorithm is not lossless, because it is subject to roundoff errors in
  730. various calculations.  The maximum error is a few counts in any one pixel
  731. value; it's highly unlikely that this could be perceived by the human eye,
  732. but it might be a concern if you are doing machine processing of an image.
  733.  
  734. At this minimum-loss setting, regular JPEG produces files that are perhaps
  735. half the size of an uncompressed 24-bit-per-pixel image.  True lossless JPEG
  736. provides roughly the same amount of compression, but it guarantees
  737. bit-for-bit accuracy.
  738.  
  739. If you have an application requiring lossless storage of images with less
  740. than 6 bits per pixel (per color component), you may want to look into the
  741. JBIG bilevel image compression standard.  This performs better than JPEG
  742. lossless on such images.  JPEG lossless is superior to JBIG on images with
  743. 6 or more bits per pixel; furthermore, it is public domain, while the JBIG
  744. techniques are heavily covered by patents.
  745.  
  746.  
  747. [10]  Why all the argument about file formats?
  748.  
  749. Strictly speaking, JPEG refers only to a family of compression algorithms;
  750. it does *not* refer to a specific image file format.  The JPEG committee was
  751. prevented from defining a file format by turf wars within the international
  752. standards organizations.
  753.  
  754. Since we can't actually exchange images with anyone else unless we agree on
  755. a common file format, this leaves us with a problem.  In the absence of
  756. official standards, a number of JPEG program writers have just gone off to
  757. "do their own thing", and as a result their programs aren't compatible with
  758. anybody else's.
  759.  
  760. The closest thing we have to a de-facto standard JPEG format is some work
  761. that's been coordinated by people at C-Cube Microsystems.  They have defined
  762. two JPEG-based file formats:
  763.   * JFIF (JPEG File Interchange Format), a "low-end" format that transports
  764.     pixels and not much else.
  765.   * TIFF/JPEG, aka TIFF 6.0, an extension of the Aldus TIFF format.  TIFF is
  766.     a "high-end" format that will let you record just about everything you
  767.     ever wanted to know about an image, and a lot more besides :-).  TIFF is
  768.     a lot more complex than JFIF, and may well prove less transportable,
  769.     because different vendors have historically implemented slightly different
  770.     and incompatible subsets of TIFF.  It's not likely that adding JPEG to the
  771.     mix will do anything to improve this situation.
  772. Both of these formats were developed with input from all the major vendors
  773. of JPEG-related products; it's reasonably likely that future commercial
  774. products will adhere to one or both standards.
  775.  
  776. I believe that Usenet should adopt JFIF as the replacement for GIF in
  777. picture postings.  JFIF is simpler than TIFF and is available now; the
  778. TIFF 6.0 spec has only recently been officially adopted, and it is still
  779. unusably vague on some crucial details.  Even when TIFF/JPEG is well
  780. defined, the JFIF format is likely to be a widely supported "lowest common
  781. denominator"; TIFF/JPEG files may never be as transportable.
  782.  
  783. A particular case that people may be interested in is Apple's QuickTime
  784. software for the Macintosh.  QuickTime uses a JFIF-compatible format wrapped
  785. inside the Mac-specific PICT structure.  Conversion between JFIF and
  786. QuickTime JPEG is pretty straightforward, and several Mac programs are
  787. available to do it (see Mac portion of section 6A).  If you have an editor
  788. that handles binary files, you can strip a QuickTime JPEG PICT down to JFIF
  789. by hand; see section 11 for details.
  790.  
  791. Another particular case is Handmade Software's shareware JPEG programs
  792. (GIF2JPG/JPG2GIF for MS-DOS, Image Alchemy for MS-DOS and a few Unix
  793. platforms).  These programs are capable of reading and writing JFIF format.
  794. By default, though, they write a proprietary format developed by HSI.
  795. This format is NOT readable by any non-HSI programs and should not be
  796. used for Usenet postings.  Use the -j switch to get JFIF output.
  797.  
  798.  
  799. [11]  How do I recognize which file format I have, and what do I do about it?
  800.  
  801. If you have an alleged JPEG file that your software won't read, it's likely
  802. to be HSI format or some other proprietary JPEG-based format.  You can tell
  803. what you have by inspecting the first few bytes of the file:
  804.  
  805. 1.  A JFIF-standard file will start with the characters (hex) FF D8 FF E0,
  806.     followed by two variable bytes, followed by 'JFIF'.  (If you see FF D8
  807.     but not the rest of it, you may have a "raw JPEG" file.  This is probably
  808.     decodable by JFIF software --- it's worth a try, anyway.)
  809.  
  810. 2.  HSI files start with 'hsi1'.  You're out of luck unless you own HSI
  811.     software.  Portions of the file may look like plain JPEG data, but they
  812.     won't decompress properly with non-HSI programs.
  813.  
  814. 3.  A Macintosh PICT file, if JPEG-compressed, will have a couple hundred
  815.     bytes of header followed by a JFIF header (scan for 'JFIF').  Strip off
  816.     everything before the FF D8 and you should be able to read it.
  817.  
  818. 4.  Anything else: it's a proprietary format, or not JPEG at all.  If you are
  819.     lucky, the file may consist of a header and a raw JPEG data stream.
  820.     If you can identify the start of the JPEG data stream (look for FF D8),
  821.     try stripping off everything before that.
  822.  
  823. In uuencoded Usenet postings, the characteristic JFIF pattern is
  824.  
  825.     "begin" line
  826.     M_]C_X ...
  827.  
  828. whereas uuencoded HSI files will start with
  829.  
  830.     "begin" line
  831.     M:'-I ...
  832.  
  833. If you learn to check for the former, you can save yourself the trouble of
  834. downloading non-JFIF files.
  835.  
  836.  
  837. [12]  What about arithmetic coding?
  838.  
  839. The JPEG spec defines two different "back end" modules for the final output
  840. of compressed data: either Huffman coding or arithmetic coding is allowed.
  841. The choice has no impact on image quality, but arithmetic coding usually
  842. produces a smaller compressed file.  On typical images, arithmetic coding
  843. produces a file 5 or 10 percent smaller than Huffman coding.  (All the
  844. file-size numbers previously cited are for Huffman coding.)
  845.  
  846. Unfortunately, the particular variant of arithmetic coding specified by the
  847. JPEG standard is subject to patents owned by IBM, AT&T, and Mitsubishi.
  848. Thus *you cannot legally use arithmetic coding* unless you obtain licenses
  849. from these companies.  (The "fair use" doctrine allows people to implement
  850. and test the algorithm, but actually storing any images with it is dubious
  851. at best.)
  852.  
  853. At least in the short run, I recommend that people not worry about
  854. arithmetic coding; the space savings isn't great enough to justify the
  855. potential legal hassles.  In particular, arithmetic coding *should not*
  856. be used for any images to be exchanged on Usenet.
  857.  
  858. There is some small chance that the legal situation may change in the
  859. future.  Stay tuned for further details.
  860.  
  861.  
  862. [13]  Does loss accumulate with repeated compression/decompression?
  863.  
  864. It would be nice if, having compressed an image with JPEG, you could
  865. decompress it, manipulate it (crop off a border, say), and recompress it
  866. without any further image degradation beyond what you lost initially.
  867. Unfortunately THIS IS NOT THE CASE.  In general, recompressing an altered
  868. image loses more information, though usually not as much as was lost the
  869. first time around.
  870.  
  871. The next best thing would be that if you decompress an image and recompress
  872. it *without changing it* then there is no further loss, i.e., you get an
  873. identical JPEG file.  Even this is not true; at least, not with the current
  874. free JPEG software.  It's essentially a problem of accumulation of roundoff
  875. error.  If you repeatedly compress and decompress, the image will eventually
  876. degrade to where you can see visible changes from the first-generation
  877. output.  (It usually takes many such cycles to get visible change.)
  878. One of the things on our to-do list is to see if accumulation of error can
  879. be avoided or limited, but I am not optimistic about it.
  880.  
  881. In any case, the most that could possibly be guaranteed would be that
  882. compressing the unmodified full-color output of djpeg, at the original
  883. quality setting, would introduce no further loss.  Even such simple changes
  884. as cropping off a border could cause further roundoff-error degradation.
  885. (If you're wondering why, it's because the pixel-block boundaries move.
  886. If you cropped off only multiples of 16 pixels, you might be safe, but
  887. that's a mighty limited capability!)
  888.  
  889. The bottom line is that JPEG is a useful format for archival storage and
  890. transmission of images, but you don't want to use it as an intermediate
  891. format for sequences of image manipulation steps.  Use a lossless format
  892. (PPM, RLE, TIFF, etc) while working on the image, then JPEG it when you are
  893. ready to file it away.  Aside from avoiding degradation, you will save a lot
  894. of compression/decompression time this way :-).
  895.  
  896.  
  897. [14]  What are some rules of thumb for converting GIF images to JPEG?
  898.  
  899. As stated earlier, you *will* lose some amount of image information if you
  900. convert an existing GIF image to JPEG.  If you can obtain the original
  901. full-color data the GIF was made from, it's far better to make a JPEG from
  902. that.  But if you need to save space and have only the GIF to work from,
  903. here are some suggestions for getting maximum space savings with minimum
  904. loss of quality.
  905.  
  906. The first rule when converting a GIF library is to look at each JPEG, to
  907. make sure you are happy with it, before throwing away the corresponding GIF;
  908. that will give you a chance to re-do the conversion with a higher quality
  909. setting if necessary.  Some GIFs may be better left as GIFs, as explained in
  910. section 3; in particular, cartoon-type GIFs with sixteen or fewer colors
  911. don't convert well.  You may find that a JPEG file of reasonable quality
  912. will be *larger* than the GIF.  (So check the sizes too.)
  913.  
  914. Experience to date suggests that large, high-visual-quality GIFs are the best
  915. candidates for conversion to JPEG.  They chew up the most storage so offer
  916. the most potential savings, and they convert to JPEG with least degradation.
  917. Don't waste your time converting any GIF much under 100 Kbytes.  Also, don't
  918. expect JPEG files converted from GIFs to be as small as those created
  919. directly from full-color originals.  To maintain image quality you may have
  920. to let the converted files be as much as twice as big as straight-through
  921. JPEG files would be (i.e., shoot for 1/2 or 1/3rd the size of the GIF file,
  922. not 1/4th as suggested in earlier comparisons).
  923.  
  924. Many people have developed an odd habit of putting a large constant-color
  925. border around a GIF image.  While useless, this was nearly free in terms of
  926. storage cost in GIF files.  It is NOT free in JPEG files, and the sharp
  927. border boundary can create visible artifacts ("ghost" edges).  Do yourself
  928. a favor and crop off any border before JPEGing.  (If you are on an X Windows
  929. system, XV's manual and automatic cropping functions are a very painless
  930. way to do this.)
  931.  
  932. cjpeg's default Q setting of 75 is appropriate for full-color input, but
  933. for GIF inputs, Q settings of 85 to 95 often seem to be necessary to avoid
  934. image degradation.  (If you apply smoothing as suggested below, the higher
  935. Q setting may not be necessary.)
  936.  
  937. Color GIFs of photographs or complex artwork are usually "dithered" to fool
  938. your eye into seeing more than the 256 colors that GIF can actually store.
  939. If you enlarge the image, you will see that adjacent pixels are often of
  940. significantly different colors; at normal size the eye averages these pixels
  941. together to produce the illusion of an intermediate color value.  The
  942. trouble with dithering is that, to JPEG, it looks like high-spatial-frequency
  943. color noise; and JPEG can't compress noise very well.  The resulting JPEG
  944. file is both larger and of lower image quality than what you would have
  945. gotten from JPEGing the original full color image (if you had it).
  946. To get around this, you want to "smooth" the GIF image before compression.
  947. Smoothing averages together nearby pixels, thus approximating the color that
  948. you thought you saw anyway, and in the process getting rid of the rapid
  949. color changes that give JPEG trouble.  Appropriate use of smoothing will
  950. often let you avoid using a high Q factor, thus further reducing the size of
  951. the compressed file, while still obtaining a better-looking output image
  952. than you'd get without smoothing.
  953.  
  954. With the V4 free JPEG software (or products based on it), a simple smoothing
  955. capability is built in.  Try "-smooth 10" or so when converting GIFs.
  956. Values of 10 to 25 seem to work well for high-quality GIFs.  Heavy-handed
  957. dithering may require larger smoothing factors.  (If you can see regular
  958. fine-scale patterns on the GIF image even without enlargement, then strong
  959. smoothing is definitely called for.)  Too large a smoothing factor will blur
  960. the output image, which you don't want.  If you are an image processing
  961. wizard, you can also do smoothing with a separate filtering program, such as
  962. pnmconvol from the PBMPLUS package.  However, cjpeg's built-in smoother is
  963. a LOT faster than pnmconvol...
  964.  
  965.  
  966. ---------------------
  967.  
  968. For more information about JPEG in general or the free JPEG software in
  969. particular, contact the Independent JPEG Group at jpeg-info@uunet.uu.net.
  970.  
  971. -- 
  972.             tom lane
  973.             organizer, Independent JPEG Group
  974. Internet: tgl@cs.cmu.edu    BITNET: tgl%cs.cmu.edu@carnegie
  975.  
  976.  
  977.